<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

/**
 * Class UserActivity
 *
 * @package App\Model
 * @mixin \Eloquent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity query()
 * @property int $id
 * @property int|null $user_id
 * @property int|null $type 活动类型
 * @property string|null $keyword 关键字
 * @property string|null $media_id 微信素材id
 * @property string|null $media_path 素材本地地址
 * @property string|null $media 素材
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity whereKeyword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity whereMedia($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity whereMediaId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity whereMediaPath($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserActivity whereUserId($value)
 */
class UserActivity extends Model
{
    protected $table = "user_activity";

    protected $fillable = ["id", 'user_id', 'type', 'keyword', 'media_id', 'media_path', 'media' ];

    /**
     * @param $open_id
     * @return \Illuminate\Support\Collection
     */
    public function getMediaId($open_id)
    {
        $mediaId =  \DB::table('user_detail as t1')
            ->leftJoin("user_activity as t2", 't1.user_id','=','t2.user_id')
            ->where("t1.open_id",'=',$open_id)
            ->pluck("t2.media_id");

        return $mediaId;
    }
}
